#include <stdio.h>
int main(){
	int x = 0;
	int y = 0;
	scanf("%d %d",&x,&y);
	if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
		printf("31");
	}else{if(y==2){
		int z = x%4;
		int b = x%100;
		int a = x%400;
		if(z==0&&b!=0||a==0){printf("29");
		}else{printf("28");}
	
	}else{printf("30");}}
	return 0;
}
